package org.corf.comm.jms;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;

import org.corf.processor.CorfProcessor;

/**
 * For the time being, the objects need to be passed already set up.
 */
public class RichConsumer {

    // -------------------------------------------------------------------------------------------------------------------------------------
    // Class constants.
    // -------------------------------------------------------------------------------------------------------------------------------------

    public static final AtomicLong GLOBAL_MESSAGE_COUNT = new AtomicLong();

    public static class Builder {
        private String name;
        private Session session;
        private Destination destination;
        private String destinationUri;
        private MessageConsumer consumer;
        private MessageListener listener;

        public Builder() {
        }

        void setName(String name) {
            this.name = name;
        }

        void setSession(Session session) {
            this.session = session;
        }

        void setDestination(Destination destination) {
            this.destination = destination;
        }

        void setDestinationUri(String destinationUri) {
            this.destinationUri = destinationUri;
        }

        void setConsumer(MessageConsumer consumer) {
            this.consumer = consumer;
        }

        void setListener(MessageListener listener) {
            this.listener = listener;
        }

        Builder withName(String name) {
            setName(name);
            return this;
        }

        Builder withSession(Session session) {
            setSession(session);
            return this;
        }

        Builder withDestination(Destination destination) {
            setDestination(destination);
            return this;
        }

        Builder withDestinationUri(String destinationUri) {
            setDestinationUri(destinationUri);
            return this;
        }

        Builder withConsumer(MessageConsumer consumer) {
            setConsumer(consumer);
            return this;
        }

        RichConsumer build() {
            RichConsumer h = new RichConsumer(name, session, destination, destinationUri, consumer, listener);
            return h;
        }
    }

    private final String name;
    private final Session session;
    private final Destination destination;
    private final String destinationUri;
    private MessageConsumer consumer;
    private MessageListener listener;

    public RichConsumer(String name, Session session, Destination destination, String destinationUri, MessageConsumer consumer,
            MessageListener listener) {
        this.name = name;
        this.session = session;
        this.destination = destination;
        this.destinationUri = destinationUri;
        this.consumer = consumer;
        this.listener = listener;
    }

    public String getName() {
        return name;
    }

    public String getDestinationUri() {
        return destinationUri;
    }

}
